<% title t('search.index.title') %>
<div class="align_left allies_nav_left">
  <%= link_to t('allies.index.view_all_allies'), allies_path %>
</div>
<div class="align_right">
  <%= render 'form' %>
</div>
<div class="clear"></div>

<div class="spacer"></div>

<div class="allies_list">
  <% if @matching_users.present? %>
    <% @matching_users.each do |user| %>
        <div class="ally center">
          <%= ProfilePicture.fetch(user.avatar.url, 'profile_picture') %>
          <h1 class="ally_name"><%= link_to user.name, profile_index_path(uid: get_uid(user.id)) %></h1>
          <div class="location"><%= user.location %></div>

          <% if current_user.allies_by_status(:pending_from_ally).include?(user) %>
            <%= link_to t('allies.cancel_ally_request'), remove_allies_path(ally_id: user.id), :method => :post, data: { confirm: t('common.actions.confirm') } %>
          <% elsif current_user.allies_by_status(:pending_from_user).include?(user) %>
            <%= link_to t('allies.accept'), add_allies_path(ally_id: user.id), :method => :post %>
          <% elsif current_user.allies_by_status(:accepted).include?(user) %>
            <%= link_to t('common.actions.remove'), remove_allies_path(ally_id: user.id), :method => :post, data: { confirm: t('common.actions.confirm') } %>
          <% else %>
            <%= link_to t('allies.add_ally'), add_allies_path(ally_id: user.id), :method => :post %>
          <% end %>
        </div>
    <% end %>
  <% else %>
    <%= t('search.index.user_not_found', email: @email_query) %>
  <% end %>
</div>
